package com.sanjiahantang.youjiarole.utils;

import android.util.Log;

import com.sanjiahantang.youjiarole.config.ConfigValue;

import java.io.File;

/**
 * Created by yan on 2017/12/13.
 * 文件工具类
 */

public class FileUtils {

    private static final String TAG = "FileUtils";

    /**
     * 删除单个文件
     *
     * @param path 要删除的文件全路径
     * @return 文件删除成功则返回true
     */
    public static boolean deleteFile(String path) {
        File file = new File(path);
        if (file.exists()) {
            boolean isDeleted = file.delete();
            Log.w(TAG, file.getName() + "删除结果：" + isDeleted);
            return isDeleted;
        } else {
            Log.w(TAG, "文件删除失败：文件不存在！");
            return false;
        }
    }

    public static String rePath(String path){
        if (path == null){
            return ConfigValue.IMG_IP;
        }

        if (path.length() < "http".length()){
            return ConfigValue.IMG_IP + path;
        }

        if (path.toLowerCase().indexOf("http") != 0){
            path = ConfigValue.IMG_IP + path;
        }

        return path.replaceAll("\\\\", "/");
    }
}
